package com.example.demo.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.demo.db1.mapper.MyTableMapper1;
import com.example.demo.entity.MyTable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;

/**
 * @Author yfy2001
 * @date 2024/6/7 13:51
 */
@Service
@DS("mysql1")
public class MyTableService1 {

    @Resource
    private MyTableMapper1 myTableMapper1;

    List<Future<List<MyTable>>> futures = new ArrayList<>();

    public List<MyTable> getDataFromAllTablesById(Integer id) {
        List<MyTable> result = new ArrayList<>();
        String[] tables1 = {"t1", "t2", "t3", "t4", "t5"};
        for (String table : tables1) {
            result.addAll(getData(table,id));
        }
        return result;
    }


    private List<MyTable> getData(String tableName,Integer id){
      return myTableMapper1.selectListFromTableById(tableName,id);
    }

    public int batchInsertData(String tableName,List<MyTable> data){
        return myTableMapper1.batchInsert(tableName,data);
    }


}